<template>
    <div class="list">
        <mt-header title="费用登记" fixed>
            <mt-button icon="back" slot="left" @click="backNative"></mt-button>
            <mt-button slot="right" @click="edits" v-if="!isEdit">编辑</mt-button>
            <mt-button slot="right" @click="edits" v-else="isEdit">取消</mt-button>
        </mt-header>
        <div class="block"></div>
        <div class="main">
            <!--repeat-->
            <div class="dayItem" v-for="s in list">
                <div class="dates">
                    {{s.reportDate}}
                </div>
                <div class="doList">
                    <div class="doItem" v-for="l in s.expenses">
                        <div class="icon" v-if="!isEdit"></div>
                        <div class="icon cut" v-if="isEdit" @click="deleteItem(l.id)"></div>
                        <div class="itemlayout" :class="{isedit:isEdit}">
                            <div class="times">{{l.reportTime}}</div>
                            <div class="infos">
                                {{l.context}}
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
        <router-link to="/add" v-if="!isEdit">
            <mt-button type="primary" class="isBtn">添加费用</mt-button>
        </router-link>
        <mt-button type="primary" class="isBtn" v-else="isEdit" @click="edits">确定</mt-button>
        <div class="block"></div>

    </div>
</template>

<script>
    import {MessageBox} from 'mint-ui';
    import Axios from 'axios'
    export default {
        name: 'list',
        data(){
            return {
                isEdit: false,
                list: {}
            }
        },
        mounted(){
            this.$nextTick(() => {
                this.getList();
            })
        },
        methods: {
            getList(){
                // let appToken = 'appToken=KppXcvUJIi+i5+lYvSk//q2nvLSdnnkVVjoE5TBv7Zu8eV0pVsf0uOn93nJc6sUQj1818Ud2HNn3G4lJRNTYskkpaEDhgoCr';
                let url = 'http://192.168.1.111:80/mylng_logistic/services/logisticsApp/getExpense.do';
                let data = {
                    taskNumber: 'T2017041200041',
                    appToken:'KppXcvUJIi+i5+lYvSk//q2nvLSdnnkVVjoE5TBv7Zu8eV0pVsf0uOn93nJc6sUQj1818Ud2HNn3G4lJRNTYskkpaEDhgoCr'
                };
                Axios.post(url,data)
                    .then(resp => {
                        this.list = resp.data.data;
                        console.log(resp.data.data)
                    }).catch(error => {
                    console.log(error)
                });
            },
            //空方法，返回APP
            backNative(){
                alert(111);
            },
            edits(){
                this.isEdit = !this.isEdit;
            },
            deleteItem(id){
                MessageBox.confirm('删除后将从列表中删除这条信息数据', '是否删除这条信息').then(action => {
                    console.log(id);
                    let url = 'http://192.168.1.111:80/mylng_logistic/services/logisticsApp/delExpense.do';
                    let data = {
                        id:id,
                        appToken:'KppXcvUJIi+i5+lYvSk//q2nvLSdnnkVVjoE5TBv7Zu8eV0pVsf0uOn93nJc6sUQj1818Ud2HNn3G4lJRNTYskkpaEDhgoCr'
                    };
                    Axios.post(url,data)
                        .then( resp => {
                            this.getList();
                        }).catch(error => {
                            console.log(error);
                    })
                });
//                //删除当前选中
//                Axios.post().then()
            }
        }
    }
</script>

<style lang="scss">
    @import "../scss/list.scss";
</style>
